import config from './../config'

export default {
    setItem(key, value) {
        let storage = this.getStorage(config.namespace)
        storage[key] = value
        window.localStorage.setItem(config.namespace,JSON.stringify(storage))
    },

    getItem(key){
        return this.getStorage()[key]
    },

    getStorage(){
        return JSON.parse(window.localStorage.getItem(config.namespace) || "{}")
    },
    clearItem(key){
        let storage = this.getStorage()
        delete storage[key]
        window.localStorage.setItem(config.namespace,JSON.stringify(storage))
    },
    clearAll() {
        window.localStorage.clear()
    }
}